/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package notificacoes;

import java.net.*;
import java.io.*;

public class EnviarSms implements Runnable {

    private String proxy_ip = "3128";
    private String proxy_port = "10.65.16.2";
    private String senha = "orange";
    private String login = "ORA685558";
    private String URLName = "";
    private boolean proxy = false;

    public void enviar(Destinatario destinatario) {
        URLName = ("http://www.fastsms.com.br/sms.cfm?id=" + login + "&senha=" + senha + "&"
                + "para=" + destinatario.getDdd_cel().charAt(0) + destinatario.getDdd_cel().charAt(1)
                + destinatario.getNum_cel() + "&texto=" + destinatario.getMensagem().replace(' ', '+'));
        Thread t = new Thread(this, URLName);
        t.start();
    }

    public void run() {
        try {
            DataInputStream di = null;
            byte[] b = new byte[1];

            // PROXY setar o proxy
            if (proxy) {
                System.setProperty("http.proxyHost", proxy_port);
                System.setProperty("http.proxyPort", proxy_ip);
            }

            URL u = new URL(URLName);
            HttpURLConnection con = (HttpURLConnection) u.openConnection();
            //
            // it's not the greatest idea to use a sun.misc.* class
            // Sun strongly advises not to use them since they can
            // change or go away in a future release so beware.
            //
//      sun.misc.BASE64Encoder encoder = new sun.misc.BASE64Encoder();
//      String encodedUserPwd =
//         encoder.encode("mydomain\\MYUSER:MYPASSWORD".getBytes());
//      con.setRequestProperty
//         ("Proxy-Authorization", "Basic " + encodedUserPwd);
            // PROXY ----------

            di = new DataInputStream(con.getInputStream());
           while (-1 != di.read(b, 0, 1)) {
             System.out.print(new String(b));
           }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    public static void main(String[] args) {
        new EnviarSms().enviar(new Destinatario (1,"doc", "xxx", "75", "88154136", "teste", "fernandus16@gmail.com"));
    }
    public String getLogin() {
        return login;
    }

    public String getURLName() {
        return URLName;
    }

    public boolean isProxy() {
        return proxy;
    }

    public void setProxy(boolean proxy) {
        this.proxy = proxy;
    }

    public void setLogin(String login) {
        this.login = login;
    }

    public String getProxy_ip() {
        return proxy_ip;
    }

    public void setProxy_ip(String proxy_ip) {
        this.proxy_ip = proxy_ip;
    }

    public String getProxy_port() {
        return proxy_port;
    }

    public void setProxy_port(String proxy_port) {
        this.proxy_port = proxy_port;
    }

    public String getSenha() {
        return senha;
    }

    public void setSenha(String senha) {
        this.senha = senha;
    }
    
}
